package io.xccit.deepseek.controller;

import io.xccit.deepseek.entity.ChatEntity;
import io.xccit.deepseek.service.OllamaService;
import org.springframework.ai.chat.ChatClient;
import org.springframework.ai.chat.ChatResponse;
import org.springframework.ai.chat.messages.UserMessage;
import org.springframework.ai.chat.prompt.Prompt;
import org.springframework.ai.ollama.OllamaChatClient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import reactor.core.publisher.Flux;

import java.util.Map;

/**
 * @author CH_ywx
 * @version 1.0
 * @create 2025/4/7
 * <p>Ollama控制类</p>
 */
@RestController
@RequestMapping("/ai")
public class OllamaController {

    private final OllamaService ollamaService;

    @Autowired
    public OllamaController(OllamaService ollamaService) {
        this.ollamaService = ollamaService;
    }

    /**
     * 聊天 返回文本
     * @param message 消息(提示词)
     * @return
     */
    @GetMapping("/chat/generate")
    public Map<String, Object> chat(@RequestParam("message") String message) {
        return ollamaService.chat(message);
    }

    /**
     * 聊天 返回流式数据
     * @param message 消息(提示词)
     * @return
     */
    @GetMapping("/chat/stream")
    public Flux<ChatResponse> chatStream(@RequestParam("message") String message){
        return ollamaService.chatStream(message);
    }


    /**
     * 询问医生接口
     * @param chatEntity
     */
    @PostMapping("/chat/doctor")
    public void chatDoctor(@RequestBody ChatEntity chatEntity){
        ollamaService.chatDoctor(chatEntity);
    }
}
